package config

import (
	"github.com/spf13/viper"
)

type Aqie struct {
	DbInfo DbInfo `yaml:"Aqie"`
}
type DbInfo struct {
	Host    string `yaml:"host"`
	Port    int    `yaml:"port"`
	Timeout string `yaml:"timeout"`
	Db      string `yaml:"db"`
	User    string `yaml:"user"`
	Pwd     string `yaml:"pwd"`
	Cron    string `yaml:"cron"`
}

func ReadSetting() (Aqie, error) {
	var settingS Aqie
	vp := viper.New()
	vp.AddConfigPath("config")
	vp.SetConfigName("config-dev")
	vp.SetConfigType("yml")
	err := vp.ReadInConfig()
	// 优先读取dev后缀的配置文件
	if err != nil {
		vp.SetConfigName("config")
		err := vp.ReadInConfig()
		if err != nil {
			return settingS, err
		}
	}
	err = vp.UnmarshalKey("aqie", &settingS.DbInfo)
	if err != nil {
		return settingS, err
	}
	return settingS, nil
}
